import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';
import 'package:spree/pages/invite/statistics/statistics.dart';
import 'package:spree/pages/invite/toInvite/to_invite.dart';
import 'package:spree/widgets/common_container.dart';
import 'package:spree/widgets/vip_content_box.dart';
import 'package:spree/widgets/vip_rectangle_box.dart';

import '../../provider/model/user_model.dart';
import 'forms/forms.dart';

class ReferalPage extends StatefulWidget {
  ReferalPage({Key? key}) : super(key: key);

  @override
  State<ReferalPage> createState() => _ReferalPageState();
}

class _ReferalPageState extends State<ReferalPage>
    with TickerProviderStateMixin {
  List _tabs2 = ["To Invite", "Forms", "Statistics"];
  late TabController _tabController;
  int fIndex = 0;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _tabController = TabController(length: _tabs2.length, vsync: this);
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            SvgPicture.asset('images/BETSPREELOGO.svg'),
            Consumer<UserModel>(builder: (context, value, child) {
              return _circleMoney(
                  money:
                      '${value.accountAmount != '' ? value.accountAmount : '0.00'}');
            })
          ],
        ),
      ),
      body: CommonContainer(
        child: ListView(
          children: [
            TabBar(
              controller: _tabController,
              indicator: const UnderlineTabIndicator(
                  borderSide: BorderSide(width: 2.0, color: Colors.red)),
              tabs: _tabs2
                  .map((e) => Tab(
                        text: e,
                      ))
                  .toList(),
              onTap: (i) {
                setState(() {
                  fIndex = i;
                });
              },
            ),
          _tabChange()
          ],
        ),
      ),
    );
  }
  Widget _tabChange(){
    if (fIndex == 0) {
      return ToInvite();
    }
    if (fIndex == 1) {
      return FormsPage();
    }
    if (fIndex == 2) {
      return Statistics();
    }
    return Container();
  }

  _circleMoney({double? width, String? money}) {
    return Row(
      children: [
        Container(
          width: width,
          margin: EdgeInsets.only(left: 12),
          padding: EdgeInsets.only(top: 4, bottom: 4, left: 8, right: 8),
          decoration: BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(20.0)),
              border: Border.all(color: Color(0xFF9C4EFF), width: 1)),
          child: Row(
            children: [
              Container(
                width: 24,
                height: 24,
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: Color(0xFF9174FB),
                    borderRadius: BorderRadius.all(Radius.circular(12.0))),
                child: Text(
                  "R\$",
                  style: TextStyle(
                    fontSize: 10,
                    color: Colors.white,
                  ),
                ),
              ),
              Padding(
                padding: EdgeInsets.only(left: 5),
                child: Text(
                  money ?? '',
                  style: TextStyle(
                    fontSize: 10,
                    color: Colors.white,
                  ),
                ),
              )
            ],
          ),
        ),
        Padding(
          padding: EdgeInsets.only(left: 20),
          child: GestureDetector(
            onTap: (){
              Navigator.pushNamed(context, 'WithdrawnPage');
            },
            child: Image.asset(
            'images/wallet-app-bar.png',
            width: 24,
          ),
          ),
        )
      ],
    );
  }
}
